package com.knight.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author knight
 */
//@Component //通过component注解可以使用Filter
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init method");
    }

    @Override
    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain)
            throws IOException, ServletException {
        System.out.println("doFilter method");
        long start = System.currentTimeMillis();
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("---消耗时间:" + (System.currentTimeMillis() - start));
    }

    @Override
    public void destroy() {
        System.out.println("destroy method");
    }
}
